<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="net.doglog.*" %>
<%@ page import="java.util.*" %>

<%@ include file="/header.jsp" %>
<%
List<Post> posts = (List<Post>) request.getAttribute("posts");
if (posts.size() == 0) {
	BlogUtil.printError(out, Blog.errorNoPostFound);
} else {
%>
<ul class="posts">
<% for (Post post : posts) { %>
	<li>
<div class="post">
	<h3><a class="anchor" href="/post/<%= post.getId() %>"><%= post.getTitle() %></a></h3>
	<span class="hint"><%= Blog.author %> 发表于 <%= PostUtil.formatTime(post.getTime()) %></span>
	<a class="anchor" href="/post/<%= post.getId() %>#comment">评论</a>
	<span><%= PostUtil.formatTags(post.getTags()) %></span>
	<% int excerptLeft = post.getContent().length() - Blog.excerptLength; %>
	<% if (excerptLeft > 0) { %>
	<div><%= post.getContent().substring(0, Blog.excerptLength) %><em><a href="/post/<%= post.getId() %>">[...]</a></em></div>
	<span class="hint">
		<a href="/post/<%= post.getId() %>">点击这里继续阅读这篇文章（还有大约<%= excerptLeft %>字）</a>
	</span>
	<% } else { %>
	<div><%= post.getContent() %></div>
	<% } %>
</div>
	</li>
<% } %>
</ul>
<div id="pager">
<%
Boolean hasPrevPage = (Boolean) request.getAttribute("hasPrevPage");
Boolean hasNextPage = (Boolean) request.getAttribute("hasNextPage");
if (hasPrevPage == null) hasPrevPage = false;
if (hasNextPage == null) hasNextPage = false;
int pageNumber = BlogUtil.parsePageNumber(request.getParameter("page"));
%>
<% if (hasPrevPage) { %>
	<span class="prevpage"><a href="/?page=<%= pageNumber-1 %>"><%= Blog.hintPrevPage %></a></span>
<% } %>
<% if (hasNextPage) { %>
	<span class="nextpage"><a href="/?page=<%= pageNumber+1 %>"><%= Blog.hintNextPage %></a></span>
<% } %>
</div>
<% } // end if (posts.size() == 0) %>
<%@ include file="/footer.jsp" %>
